<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "{{%base_goods_qg}}".
 *
 * @property integer $qgd_id
 * @property integer $status
 * @property string $qgczrz
 * @property string $spm
 * @property string $gg
 * @property double $sczdj
 * @property integer $qgsl
 * @property string $bzqyq
 * @property double $cgjg
 * @property integer $xj
 * @property integer $cs
 * @property integer $qym
 * @property string $dhrq
 * @property string $wlsyq
 * @property string $fbsj
 * @property string $mjgs
 * @property string $mjgsdz
 * @property string $mjlxr
 * @property string $mjlxrdh
 * @property string $mjshdz
 * @property integer $statuses
 * @property integer $sp_id
 */
class BaseGoodsQg extends \yii\db\ActiveRecord {

    /**
     * @inheritdoc
     */
    public static function tableName() {
        return '{{%base_goods_qg}}';
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['status', 'qgsl', 'xj', 'cs', 'qym', 'statuses', 'sp_id', 'sum','flag'], 'integer'],
            [['qgczrz', 'mjgsdz', 'mjshdz','bz'], 'string'],
            [['sczdj', 'cgjg'], 'number'],
            [['spm', 'gg', 'bzqyq', 'dhrq', 'wlsyq', 'fbsj', 'mjgs', 'mjlxr'], 'string', 'max' => 128],
            [['mjlxrdh'], 'string', 'max' => 25]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'qgd_id' => '求购单ID',
            'status' => '求购单状态',
            'qgczrz' => '求购操作日志',
            'spm' => '商品名',
            'gg' => '规格',
            'sczdj' => '市场指导价',
            'qgsl' => '求购数量',
            'bzqyq' => '保质期要求',
            'cgjg' => '采购价格',
            'xj' => '包装要求 是否新旧 新1 旧0',
            'cs' => '残损  完好1 残存0 ',
            'qym' => '区域码  有1 无0',
            'dhrq' => '到货日期要求',
            'wlsyq' => '物流商要求',
            'fbsj' => '发布时间',
            'mjgs' => '买家公司',
            'mjgsdz' => '买家公司地址',
            'mjlxr' => 'Mjlxr',
            'mjlxrdh' => '买家联系人电话',
            'mjshdz' => '买家收货地址',
            'statuses' => '0下架  1上架',
            'sp_id' => 'Sp ID',
            'sum' => '供货商数',
             'bz' => '备注',
             'flag' => '1正常2删除',
        ];
    }

    public function addGoodsqg($data, $uid) {
        foreach ($data as $k => $v) {
            $this->$k = $v;
        }$this->fbsj = (String)time();
        $this->uid = $uid;
        if ($this->save()) {
            return true;
        } else {
            return false;
        }
    }
    
    static function getGh($qgdid) {
        $datacount = BaseGoodsGh::find()->andWhere(['qgd_id' => $qgdid,'flag'=>1])->count('id');
        if ($datacount) {
            return $datacount;
        } else {
            return 0;
        }
    }
   public static function getShdz($params) { 
           $res = BaseGoodsQg::findOne([ 'qgd_id' => $params]); 
          // echo $res['company_name'];
          //var_dump($res);
        //   die();
           $temp = $res['mjshdz'];         
           return $temp;
    }
    
    public static function getTel($params) { 
           $res = BaseGoodsQg::findOne([ 'qgd_id' => $params]); 
          // echo $res['company_name'];
          //var_dump($res);
        //   die();
           $temp = $res['mjlxrdh'];         
           return $temp;
    }
}
